#!/usr/bin/env bash

if [ $# -eq 1 ]; then
if [ $1 == 'clean' ];then
    echo -n "Cleaning ... "
    rm -rf ./log ./data *.out out
    echo "Done"
    exit 0
fi
fi
date=$(date +"%m%d-%T")
log_dir=./log/$date
data_dir=./data/$date
mkdir -p $log_dir
mkdir -p $data_dir

function dump_table {
    tb_name=$1
    data_file=$tb_name-$2.csv
    psql dev_database <<__EOF
    \copy $tb_name to '/tmp/$data_file' delimiter '|' csv header;
__EOF
    mv /tmp/$data_file $data_dir
}



echo $(date) > .out
for i in {1..1}; do
    date=$(date +"%T")
    bash ../../shell/database/db_dev.sh > $log_dir/db_dev-$date.log
    python ./SpideRandomUsers.py 2>&1 > $log_dir/users-$date.log 
    dump_table users $date
    python ./SpideUserPosts.py 2>&1 > $log_dir/posts-$date.log 
    dump_table user_reposts $date
    dump_table user_posts $date
    python ./SampleGenerator.py 2>&1 > $log_dir/sample-$date.log 
    dump_table repost_samples $date
done
echo $(date) >>.out

